//
//  ContentPlateController.m
//  微看
//
//  Created by 吴明磊 on 15/8/19.
//  Copyright © 2015年 wuminglei. All rights reserved.
//

#import "ContentPlateController.h"
#import "BaseCell.h"
#import "HeadLine.h"
#import "SVProgressHUD.h"

@interface ContentPlateController ()

@property(nonatomic,strong)NSArray *headLine;
@end
static NSString * const cellIdentifier = @"baseCell";
@implementation ContentPlateController

- (void)viewDidLoad {
    [super viewDidLoad];
    

//        self.tableView.rowHeight = 400;
    self.tableView.estimatedRowHeight = 700;
    self.tableView.rowHeight = UITableViewAutomaticDimension;

    self.view.backgroundColor = [UIColor whiteColor];
    
    [self loadInformation];
    
    self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 40, 0);
    
    [self.tableView registerClass:[BaseCell class] forCellReuseIdentifier:cellIdentifier];
}

//MARK: 方法
- (void)loadInformation {

    [HeadLine loadInformation:^(NSArray *array) {
        
        if (array) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                self.headLine = array;
                [self.tableView reloadData];
            });
        }
        
    } Error:^(NSError *error) {
        
        if (error) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                

                [SVProgressHUD showErrorWithStatus:@"网络连接错误"];
                
            });
        }
    }];
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return self.headLine.count;
    
}

- (UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {

    
    BaseCell *cell = [BaseCell baseCellWithTableView:tableView indexPath:indexPath];
    
    HeadLine *headLine = self.headLine[indexPath.row];
    
    cell.information = headLine;
    
    
    return cell;
}

//- (CGFloat)tableView:(nonnull UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
//
//    BaseCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//    
//    return [cell rowHeight];
//    
//}
@end
